define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Echarts) {

    var Controller = {
        index: function () {
            var queryDate = $("#query_date").val();

            Form.api.bindevent($("form[role=form]"));

            $(document).on("click", ".charts-custom a[data-toggle=\"tab\"]", function () {
                var that = this;
                setTimeout(function () {
                    var id = $(that).attr("href");
                    var chart = Echarts.getInstanceByDom($(id)[0]);
                    chart.resize();
                }, 0);
            });
            var option;
            /*
            var departData = [
                      ['风扇', 43.3],
                      ['电视机', 83.1],
                      ['空调', 86.4],
                      ['冰箱', 72.4],
                      ['风扇1', 43.3],
                      ['电视机1', 83.1],
                      ['空调1', 86.4],
                      ['冰箱1', 72.4]
                  ]
            */
            var departData = JSON.parse($("#feeDepart").val());
            console.log('departData =>', departData)
            var barChartDepart = Echarts.init(document.getElementById('bar-chart-depart'), 'walden');
            option = {
              tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'shadow'
                }
              },
              toolbox: {
                feature: {
                  saveAsImage: { show: true }
                }
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              xAxis: [
                {
                  type: 'category',
                  // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                  data: departData['depart'],
                  axisTick: {
                    alignWithLabel: true
                  }
                }
              ],
              yAxis: [
                {
                  type: 'value'
                }
              ],
              series: [
                {
                  name: '费用',
                  type: 'bar',
                  barWidth: '60%',
                  //data: [10, 52, 200, 334, 390, 330, 220],
                  data: departData.data,
                  itemStyle: {
                    normal: {
                      label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                          color: 'gray',
                          fontSize: 16
                        }
                      }
                    }
                  },
                }
              ]
            };
            
            // 使用刚指定的配置项和数据显示图表。
            barChartDepart.setOption(option);

            var typeData = JSON.parse($("#feeUserType").val());
            
            // var legendData = ['兼职', '实习生'];
            // var catData = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
            var legendData = typeData['type'];
            var catData = typeData['depart'];

            option = {
              tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'shadow'
                }
              },
              toolbox: {
                feature: {
                  saveAsImage: { show: true }
                }
              },
              legend: {
                data: legendData
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              xAxis: [
                {
                  type: 'category',
                  data: catData,
                  axisTick: {
                    alignWithLabel: true
                  }
                }
              ],
              yAxis: [
                {
                  type: 'value'
                }
              ],
              series: [
                {
                  name: '兼职',
                  type: 'bar',
                  // data: [10, 52, 200, 334, 390, 330, 220],
                  data: typeData['part_time'],
                  itemStyle: {
                    normal: {
                      label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                          color: 'gray',
                          fontSize: 16
                        }
                      }
                    }
                  },
                },
                {
                  name: '实习生',
                  type: 'bar',
                  // data: [10, 52, 200, 334, 390, 330, 220],
                  data: typeData['intern'],
                  itemStyle: {
                    normal: {
                      label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                          color: 'gray',
                          fontSize: 16
                        }
                      }
                    }
                  },
                }
              ]
            };

            var barChartType = Echarts.init(document.getElementById('bar-chart-type'), 'walden');
            // 使用刚指定的配置项和数据显示图表。
            barChartType.setOption(option);
            $(".btn-embossed").on("click", function() {
                queryDate = $("#query_date").val();
                Fast.api.ajax({
                    url:'pt/statistic/index?query_date=' + queryDate
                }, function(data, ret){
                    console.log('statistic =>', ret.data)
                    var res = ret.data
                    departData = res['depart'];
                    typeData = res['type'];

                    barChartDepart.setOption({
                      xAxis: [
                        {
                          type: 'category',
                          data: departData['depart'],
                          axisTick: {
                            alignWithLabel: true
                          }
                        }
                      ],
                      series: [
                        {
                          name: '费用',
                          type: 'bar',
                          barWidth: '60%',
                          data: departData['data'],
                          itemStyle: {
                            normal: {
                              label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                  color: 'gray',
                                  fontSize: 16
                                }
                              }
                            }
                          },
                        }
                      ]
                    })
                    barChartType.setOption({
                      xAxis: [
                        {
                          type: 'category',
                          data: typeData['depart'],
                          axisTick: {
                            alignWithLabel: true
                          }
                        }
                      ],
                      series: [
                        {
                          name: '兼职',
                          type: 'bar',
                          // data: [10, 52, 200, 334, 390, 330, 220],
                          data: typeData['part_time'],
                          itemStyle: {
                            normal: {
                              label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                  color: 'gray',
                                  fontSize: 16
                                }
                              }
                            }
                          },
                        },
                        {
                          name: '实习生',
                          type: 'bar',
                          // data: [10, 52, 200, 334, 390, 330, 220],
                          data: typeData['intern'],
                          itemStyle: {
                            normal: {
                              label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                  color: 'gray',
                                  fontSize: 16
                                }
                              }
                            }
                          },
                        }
                      ]
                    })
                }, function(){
                    Backend.api.toastr.error('统计错误');
                });
            })
        },
        duty: function () {
            var queryDate = $("#query_date").val();

            Form.api.bindevent($("form[role=form]"));

            $(document).on("click", ".charts-custom a[data-toggle=\"tab\"]", function () {
                var that = this;
                setTimeout(function () {
                    var id = $(that).attr("href");
                    var chart = Echarts.getInstanceByDom($(id)[0]);
                    chart.resize();
                }, 0);
            });
            var option;
            var departData = JSON.parse($("#feeDepart").val());
            console.log('departData =>', departData)
            var barChartDepart = Echarts.init(document.getElementById('bar-chart-depart'), 'walden');
            option = {
              tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'shadow'
                }
              },
              toolbox: {
                feature: {
                  saveAsImage: { show: true }
                }
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              xAxis: [
                {
                  type: 'category',
                  // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                  data: departData['depart'],
                  axisTick: {
                    alignWithLabel: true
                  }
                }
              ],
              yAxis: [
                {
                  type: 'value'
                }
              ],
              series: [
                {
                  name: '人次',
                  type: 'bar',
                  barWidth: '60%',
                  //data: [10, 52, 200, 334, 390, 330, 220],
                  data: departData.data,
                  itemStyle: {
                    normal: {
                      label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                          color: 'gray',
                          fontSize: 16
                        }
                      }
                    }
                  },
                }
              ]
            };
            
            // 使用刚指定的配置项和数据显示图表。
            barChartDepart.setOption(option);

            var typeData = JSON.parse($("#feeUserType").val());
            
            // var legendData = ['兼职', '实习生'];
            // var catData = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
            var legendData = typeData['type'];
            var catData = typeData['depart'];

            option = {
              tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'shadow'
                }
              },
              toolbox: {
                feature: {
                  saveAsImage: { show: true }
                }
              },
              legend: {
                data: legendData
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              xAxis: [
                {
                  type: 'category',
                  data: catData,
                  axisTick: {
                    alignWithLabel: true
                  }
                }
              ],
              yAxis: [
                {
                  type: 'value'
                }
              ],
              series: [
                {
                  name: '兼职',
                  type: 'bar',
                  // data: [10, 52, 200, 334, 390, 330, 220],
                  data: typeData['part_time'],
                  itemStyle: {
                    normal: {
                      label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                          color: 'gray',
                          fontSize: 16
                        }
                      }
                    }
                  },
                },
                {
                  name: '实习生',
                  type: 'bar',
                  // data: [10, 52, 200, 334, 390, 330, 220],
                  data: typeData['intern'],
                  itemStyle: {
                    normal: {
                      label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                          color: 'gray',
                          fontSize: 16
                        }
                      }
                    }
                  },
                }
              ]
            };

            var barChartType = Echarts.init(document.getElementById('bar-chart-type'), 'walden');
            // 使用刚指定的配置项和数据显示图表。
            barChartType.setOption(option);
            $(".btn-embossed").on("click", function() {
                queryDate = $("#query_date").val();
                Fast.api.ajax({
                    url:'pt/statistic/index?query_date=' + queryDate
                }, function(data, ret){
                    console.log('statistic =>', ret.data)
                    var res = ret.data
                    departData = res['depart'];
                    typeData = res['type'];

                    barChartDepart.setOption({
                      xAxis: [
                        {
                          type: 'category',
                          data: departData['depart'],
                          axisTick: {
                            alignWithLabel: true
                          }
                        }
                      ],
                      series: [
                        {
                          name: '费用',
                          type: 'bar',
                          barWidth: '60%',
                          data: departData['data'],
                          itemStyle: {
                            normal: {
                              label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                  color: 'gray',
                                  fontSize: 16
                                }
                              }
                            }
                          },
                        }
                      ]
                    })
                    barChartType.setOption({
                      xAxis: [
                        {
                          type: 'category',
                          data: typeData['depart'],
                          axisTick: {
                            alignWithLabel: true
                          }
                        }
                      ],
                      series: [
                        {
                          name: '兼职',
                          type: 'bar',
                          // data: [10, 52, 200, 334, 390, 330, 220],
                          data: typeData['part_time'],
                          itemStyle: {
                            normal: {
                              label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                  color: 'gray',
                                  fontSize: 16
                                }
                              }
                            }
                          },
                        },
                        {
                          name: '实习生',
                          type: 'bar',
                          // data: [10, 52, 200, 334, 390, 330, 220],
                          data: typeData['intern'],
                          itemStyle: {
                            normal: {
                              label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                  color: 'gray',
                                  fontSize: 16
                                }
                              }
                            }
                          },
                        }
                      ]
                    })
                }, function(){
                    Backend.api.toastr.error('统计错误');
                });
            })
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
